*Replication file for Hooghe & Oser "Partisan strength, political trust and generalized trust in the United States" in Social Science Research.

clear all
set maxvar 9000
set more off
*DATA DOWNLOAD:
*website for downloading data through 2014: http://gss.norc.org/get-the-data/stata (last accessed: 28Feb2017)
*Date for version 6 (through 2014) release: July 22, 2016 
*References resources for GSS data analysis:
***SDA: http://sda.berkeley.edu/sdaweb/analysis/?dataset=gss14
***NORC: https://gssdataexplorer.norc.org/
***GSS codebook link: https://gssdataexplorer.norc.org/documents?tab=1

sum id
label var year "Year of survey"
*sum year, detail
*tab year, miss
/*NOTE: 59,599 cases in cumulative file through 2014*/


********************************************************
*Last update:  18June2017
*Analysis conducted in Stata 14
********************************************************

*****************
*****VAR RECODES
*****************

*****
*POLITICAL TRUST BATTERY (DV)
*****
tab confed, miss
tab confed, miss nolab
gen confed_ = .
replace confed_=1 if confed==3
replace confed_=2 if confed==2
replace confed_=3 if confed==1
label var confed_ "recoded <confed>"
label define poltrust 1 "Hardly any" 2 "Only some" 3 "A great deal"
label value confed_ poltrust
tab confed_ confed, miss

tab conjudge, miss
tab conjudge, miss nolab
gen conjudge_ = .
replace conjudge_=1 if conjudge==3
replace conjudge_=2 if conjudge==2
replace conjudge_=3 if conjudge==1
label var conjudge_ "recoded <conjudge>"
label value conjudge_ poltrust
tab conjudge_ conjudge, miss

tab conlegis, miss
tab conlegis, miss nolab
gen conlegis_ = .
replace conlegis_=1 if conlegis==3
replace conlegis_=2 if conlegis==2
replace conlegis_=3 if conlegis==1
label var conlegis_ "recoded <conlegis>"
label value conlegis_ poltrust
tab conlegis_ conlegis, miss

*Creating Political Trust Mean Scale
alpha confed_ conjudge_ conlegis_, item casewise
egen pol_conf2 = rowmean(confed_ conjudge_ conlegis_)
label var pol_conf2 "Political Trust Scale"
*alpha for file through 2014 =.6619
sum pol_conf2
tab pol_conf2


*****
*GENERALIZED TRUST
*****
tab fair, miss
gen fair_=.
replace fair_=1 if fair==1
replace fair_=2 if fair==3
replace fair_=3 if fair==2
label define fair_ 1 "Take Advantage" 2 "Depends" 3 "Fair"
label var fair_ "recoded <fair>"
label values fair_ fair_
tab fair fair_

tab helpful, miss
gen helpful_=.
replace helpful_=1 if helpful==2
replace helpful_=2 if helpful==3
replace helpful_=3 if helpful==1
label define helpful_ 1 "Look out for self" 2 "Depends" 3 "Helpful"
label var helpful_ "recoded <helpful>"
label values helpful_ helpful_
tab helpful helpful_

tab trust, miss
gen trust_=.
replace trust_=1 if trust==2
replace trust_=2 if trust==3
replace trust_=3 if trust==1
label define trust_ 1 "Can't Trust" 2 "Depends" 3 "Can Trusted"
label var trust_ "recoded <trust>"
label values trust_ trust_
tab trust trust_

*Creating generalized trust mean scale
mean fair_ helpful_ trust_
alpha fair_ helpful_ trust_
alpha fair_ helpful_ trust_, item casewise
*alpha = .6667
egen gen_trust = rowmean(fair_ helpful_ trust_)
label var gen_trust "Generalize Trust Scale"
sum gen_trust


*****
*PARTY ID
*****
tab partyid, miss
tab partyid, miss nolab

*Partisan strength, not direction (i.e. not D vs R)
gen pid_strength=.
replace pid_strength=0 if partyid==3
replace pid_strength=1 if inlist(partyid,2,4)  
replace pid_strength=2 if inlist(partyid,1,5)  
replace pid_strength=3 if inlist(partyid,0,6)  
label define strength 0 "Independent" 1 "Partisan strength, leaner" 2 "Partisan strength, weak" 3 "Partisan strength, strong"
label var pid_strength "Partisan Strength, Ind as zero"
label values pid_strength strength
tab partyid pid_strength, missing

*Partisan strength v2, Independents missing
gen pid_strength2=.
replace pid_strength2=0 if inlist(partyid,2,4)  
replace pid_strength2=1 if inlist(partyid,1,5)  
replace pid_strength2=2 if inlist(partyid,0,6)  
label var pid_strength2 "Partisan Strength, Inds missing"
label define pid_strength2 0 "Leaner" 1 "Weak" 2 "Strong"
label values pid_strength2 pid_strength2
tab partyid pid_strength2, missing

*Partisan strength recodes for diagnostic Fig summarized following Table 2 
*DEMOCRATS, 
gen dem_strength3=.
replace dem_strength3=0 if partyid==3
replace dem_strength3=1 if partyid==2
replace dem_strength3=2 if partyid==1
replace dem_strength3=3 if partyid==0
label var dem_strength3 "Strength of Dem Ident, Inds base excl Rep"
label define dem_strength3 0 "Independent" 1 "Leaner" 2 "Weak" 3 "Strong"
label values dem_strength3 dem_strength3
tab partyid dem_strength3, missing
tab dem_strength3 dem_strength, miss


*REPUBLICANS
gen rep_strength3=.
replace rep_strength3=0 if partyid==3
replace rep_strength3=1 if partyid==4
replace rep_strength3=2 if partyid==5
replace rep_strength3=3 if partyid==6
label var rep_strength3 "Strength of Rep Ident, Inds base excl Rep"
label define rep_strength3 0 "Independent" 1 "Leaner" 2 "Weak" 3 "Strong"
label values rep_strength3 rep_strength3
tab partyid rep_strength3, missing


/* CONTROLS FOR SPECIFIC PARTY ID (Dem, Rep or Ind - regardless of strength) */
tab partyid
gen rep=.
replace rep=1 if inlist(partyid,4,5,6)
replace rep=0 if inlist(partyid,0,1,2,3)
gen dem=.
replace dem=1 if inlist(partyid,0,1,2)
replace dem=0 if inlist(partyid,3,4,5,6)
gen ind=.
replace ind=1 if partyid==3
replace ind=0 if inlist(partyid,0,1,2,4,5,6)
label var rep "Republican"
label var dem "Democrat"
label var ind "Independent"
tab partyid rep, missing
tab partyid dem, missing
tab partyid ind, missing

*PID 3 category
gen pid_idr=.
replace pid_idr=0 if partyid==3
replace pid_idr=1 if inlist(partyid,0,1,2)
replace pid_idr=2 if inlist(partyid,4,5,6)
label var pid_idr "Party ID 3categ, Ind base"
label define pid_idr 0 "Independent" 1 "Specific party ID, Democrat" 2 "Specific party ID, Republican"
label values pid_idr pid_idr
tab partyid pid_idr, missing
tab pid_idr, missing
tab pid_idr, missing nolab

***************
*****SOCIO-DEM CONTROL RECODES
***************
set more off
*AGE
tab age, miss
lab var age "Age"
sum age, detail
*kdensity age

*GENDER
tab sex
tab sex, miss
tab sex, miss nolab /*male=1, female=2*/
gen gender = .
replace gender =0 if sex ==1
replace gender =1 if sex ==2
label define gender  0 "Gender, male" 1 "Gender, female"
lab var gender "Gender, female"
label values gender gender
tab sex gender, miss
tab gender, miss

*EDUCATION (years of schooling, 0-20)
tab educ
lab var educ "Education, years of schooling"
tab educ, miss
*kdensity educ

*INCOME
lab var coninc "Income, household"
sum coninc, detail
*kdensity coninc

*TV HOURS
tab tvhours
tab tvhours, miss
*kdensity tvhours /*highly skewed*/
*TV recode, creating quartile version:
gen tv_temp=tvhours if tvhours>0
tab tv_temp, miss
xtile tv_quart=tv_temp, n(4)
tab tv_quart, miss
replace tv_quart=0 if tvhours==0
tab tv_quart, miss
tab tv_quart tvhours, miss
label var tv_quart "TV hours/day"
label define tv_quart 0 "0" 1 "TV watching, very low" 2 "TV watching, low" 3 "TV watching, high" 4 "TV watching, very high"
label value tv_quart tv_quart
tab tv_quart, miss
tab tv_quart

*NEWS
tab news
tab news, miss
tab news, miss nolab
gen news_ = .
replace news_ = 1 if news==5
replace news_ = 2 if news==4
replace news_ = 3 if news==3
replace news_ = 4 if news==2
replace news_ = 5 if news==1
replace news_=. if missing(news)
label var news_ "Newspaper reading"
label define news_ 1 "Never" 2 "LT 1xwk" 3 "1xwk" 4 "Fewx wk" 5 "Everyday"
label value news_ news_
tab news_ news, miss
*histogram news_, discrete percent addlabel xtitle(News)

*RELIGIOUS SERVICE ATTENDANCE
tab attend, miss
tab attend, miss nolab
gen attend2=attend>3
replace attend2=. if missing(attend)
label var attend2 "Religious attendance, 1/month+"
label define attend2 0 "None or Less than Once per Month" 1 "Religious attendance, 1/month+"
label values attend2 attend2
tab attend2, miss
tab attend attend2, miss

*LOCATION SIZE
tab size
tab size, miss
*kdensity size
*Take log of highly skewed size variable
gen ln_size=ln(size)
label var ln_size "Size location"
sum ln_size, detail
*kdensity ln_size

*RACE
tab race
tab race, miss
tab race, miss nolab
gen black=.
replace black=1 if race==2
replace black=0 if race==1 | race==3
tab race black, miss
gen otherrace=.
replace otherrace=1 if race==3
replace otherrace=0 if race==1 | race==2
lab var black "Race, black"
lab var otherrace "Race, other"
tab race otherrace, miss

*INTERACTION VARS CODING
gen year_pid = year*pid_strength
label var year_pid "Interaction year*pid_strength"

*Mean centering variables involved in the interaction
sum year
gen year2=year-`r(mean)'
label var year2 "Year centered at mean"
sum year2

sum pid_strength
gen pidstr_c_indszero=pid_strength-`r(mean)'
label var pidstr_c_indszero "PIDstr, mean-centered, ind 0"
sum pidstr_c_indszero

sum dem_strength3
gen didstr_c_indszero=dem_strength3-`r(mean)'
label var didstr_c_indszero "DIDstr, mean-centered, ind 0"
sum didstr_c_indszero

sum rep_strength3
gen ridstr_c_indszero=rep_strength3-`r(mean)'
label var ridstr_c_indszero "DIDstr,  mean-centered, ind miss"
sum ridstr_c_indszero


*INCUMBENCY VAR CODE
tab year, miss
gen incumbency = .
replace incumbency = 1 if year >= 1972 & year <=1976
replace incumbency = 0 if year >= 1977 & year <=1980
replace incumbency = 1 if year >= 1982 & year <=1991
replace incumbency = 1 if year >= 1982 & year <=1991
replace incumbency = 0 if year >= 1993 & year <=2000
replace incumbency = 1 if year >= 2002 & year <=2008
replace incumbency = 0 if year >= 2010 & year <=2014
tab year incumbency
lab var incumbency "Incumbency"


********
*WEIGHTS
*********
*****GSS codebook notes on relevant weights: 
*Appendix A - Sampling Design and Weighting - https://gssdataexplorer.norc.org/documents/441/display
*"wtss" weights for (a) sub-sampling of non-respondents (b) number of adults in household. 
*In years prior to 2004+ a "1" is assigned to all cases, so they are effectively unweighted. 
*"wtssall" also applies weights for number of adults in the household to years prior to 2004

*****Berkeley SDA constructed a composite weight for cumulative file analyses
*For documentation through 2014, see: http://sda.berkeley.edu/D3/GSS14/Doc/hcbk.htm
*For instructions on creating composite weight, main website: http://sda.berkeley.edu/sdaweb/analysis/?dataset=gss14
*....and then input "compwt" into "variable selection" box
gen compwt = wtssall*oversamp*formwt*1.0
sum compwt
*svyset [pweight=compwt]
*svyset, clear


******************************************
*DESCRIPTIVES: variables used in analysis**
*******************************************
/*Only vars for descriptives table: 
sum pol_conf2 gen_trust pid_strength incumbency year age gender educ coninc tv_quart news_ attend2 black other ln_size 

*All relevant vars
sum pol_conf2
sum gen_trust
sum partyid
sum dem
sum rep
sum ind
sum pid_strength
sum dem_strength3
sum rep_strength3
sum incumbency
sum year
sum year2
sum age
sum gender
sum educ
sum coninc
sum attend2
sum black
sum otherrace
sum ln_size
sum news_
sum tvhours
sum tv_quart

*****
tab partyid, miss
tab pid_idr, miss
tab pid_strength, miss
tab dem_strength3, miss
tab rep_strength3, miss
tab tv_quart, miss
*/


	

***************************************************************************
***************************************************************************
*FIG 1: Trends in Partisan strength, political trust and generalized trust*
***************************************************************************
***************************************************************************
/*
corr pid_strength pol_conf2 /*.0773 thru 2012; .0783 thru 2014 */
corr pid_strength gen_trust /*.0539 thru 2012; .0553 thru 2014 */
sort year, stable

***COLLAPSE: 
preserve
collapse pid_strength pol_conf2 gen_trust, by(year)
sort year, stable

gen yr_pid_strength=100*(pid_strength/pid_strength[1])
gen yr_pol_conf=100*(pol_conf2/pol_conf2[2])
* (Note: pol_conf2 uses obs 2 as reference b/c is missing in 1972)
gen yr_gen_trust=100*(gen_trust/gen_trust[1])
corr yr_pid_strength yr_pol_conf /* through 2014: .6180, reported in paper 0.62*/

label var yr_pid_strength "Party ID Strength"
label var yr_pol_conf "Political Trust Scale"
label var yr_gen_trust "Generalized Trust Scale"

***TREND FIGURES
*Figure 1a: Partisan Strength and Political Trust
twoway (line yr_pid_strength year, sort) (line yr_pol_conf year, sort), ytitle(Year 1 = 100) xtitle(Year)

*Figure 1b: Partisan Strength and Generalized Trust
twoway (line yr_pid_strength year, sort) (line yr_gen_trust year, sort), ytitle(Year 1 = 100) xtitle(Year)

restore

*To ascertain that restore command was executed:
corr pid_strength pol_conf2 /*should read .0783*/
corr pid_strength gen_trust /*should read .0553*/
*/





******************************************************************************
******************************************************************************
* FIGURE 2: Trends in political trust and generalized trust, by party identity*
******************************************************************************
******************************************************************************
/*
***** GENERATE 3-LEVEL PID
gen pid_3 = .
replace pid_3 = 1 if inlist(partyid,0,1,2)
replace pid_3 = 2 if partyid == 3
replace pid_3 = 3 if inlist(partyid,4,5,6)

label define pid_3 1 "Democrat" 2  "Independent" 3 "Republican"
label values pid_3 pid_3
label var pid_3 "Party Identification"

tab partyid pid_3, missing
tab pid_3, missing



***** FIGURE 2a and b CODE: 

preserve
collapse pol_conf2 gen_trust [pweight = compwt], by(year pid_3)
drop if missing(pid_3)

*Fig2a
twoway (lowess pol_conf2 year if pid_3 == 1, bwidth(.4)) ///
	(lowess pol_conf2 year if pid_3 == 2, bwidth(.4)) ///
	(lowess pol_conf2 year if pid_3 == 3, bwidth(.4)), ///
	 ytitle(Political Trust) xtitle(Survey Year) ///
	 legend(order(1 "Democrat" 2  "Independent" 3 "Republican") rows(1)) ///
	 title(Lowess Smoothed Political Trust by Year and PID)

*Fig2b	 
twoway (lowess gen_trust year if pid_3 == 1, bwidth(.4)) ///
	(lowess gen_trust year if pid_3 == 2, bwidth(.4)) ///
	(lowess gen_trust year if pid_3 == 3, bwidth(.4)), ///
	 ytitle(Generalized Trust) xtitle(Survey Year) ///
	 legend(order(1 "Democrat" 2  "Independent" 3 "Republican") rows(1)) ///
	 title(Lowess Smoothed General Trust by Year and PID)

restore
*/

********* Missings investigation: Regression Analysis data preparation
********* Create a table that shows item non-response percentage for each variable by year.

* Create dummy for missing/not missing for each variable in model with missing > 5% in a given year.
set more off
gen m_pol_conf2    = missing(pol_conf2) 
gen m_gen_trust    = missing(gen_trust)
gen m_pid_strength = missing(pid_strength) 
gen m_pid_idr 	   = missing(pid_idr) 
gen m_tv_quart 	   = missing(tv_quart) 
gen m_news_ 	   = missing(news_) 
gen m_age 		   = missing(age) 
gen m_gender 	   = missing(gender) 
gen m_educ 		   = missing(educ) 
gen m_coninc 	   = missing(coninc) 
gen m_attend2 	   = missing(attend2) 
gen m_black 	   = missing(black) 
gen m_otherrace    = missing(otherrace) 
gen m_ln_size      = missing(ln_size) 
gen m_incumbency   = missing(incumbency) 

lab var m_pol_conf2    "Political Trust Scale"
lab var m_gen_trust    "Generalized Trust Scale"
lab var m_pid_strength "Partisan Strength" 
lab var m_pid_idr 	   "3 Category PID"
lab var m_tv_quart 	   "TV Hours per Day Quartiles" 
lab var m_news_ 	   "Newspaper Reading"
lab var m_age 		   "Age"
lab var m_gender 	   "Gender" 
lab var m_educ 		   "Years of Schooling" 
lab var m_coninc 	   "Household Income" 
lab var m_attend2 	   "Religious Attendance > 1/month" 
lab var m_black 	   "African American"
lab var m_otherrace    "Other Race" 
lab var m_ln_size      "Log Location Size" 
lab var m_incumbency   "Incumbency"

lab define missing 0 "Observed" 1 "Missing"
lab val m_pol_conf2 m_gen_trust m_pid_strength m_pid_idr m_tv_quart m_news_ ///
	m_age m_gender m_educ m_coninc m_attend2 m_black m_otherrace ///
	m_ln_size m_incumbency missing 
	
*For all vars, tab var & missing
foreach var of varlist pol_conf2 pid_strength pid_idr tv_quart news_ ///
	age gender educ coninc attend2 black otherrace ln_size incumbency {
	tab `var' m_`var', missing
}
*/

*For all vars, missing by year
foreach var of varlist m_pol_conf2 m_gen_trust m_pid_strength m_pid_idr m_tv_quart m_news_ ///
	m_age m_gender m_educ m_coninc m_attend2 m_black m_otherrace ///
	m_ln_size m_incumbency {
		tab year `var', row missing
	}
	
sort year
by year: tab ballot m_pol_conf2, row
by year: tab ballot m_gen_trust, row
*Less than 5% missings due to non-response all years according to this output, except for 2002 and 2004

**** Political Trust scale is missing in 1972 and 1985.
**** General Trust scale is missing in 1974, 1977, 1982, and 1985.
**** TV missing in 1972, 1973, 1974, 1976, 1984, 1987
**** Newpaper missing in 1973, 1974, 1976, 1980, 1984
**** To keep sample consistent, all of these years should be dropped

drop if inlist(year, 1972, 1973, 1974, 1976, 1977, 1980, 1982, 1984, 1985, 1987) // 15,784 observations deleted	
	


*****************************************************
*****************************************************
***REGRESSION MODELS
*****************************************************
*****************************************************


******************************
************* POLITICAL TRUST*
******************************

***TABLE 2    
/*REGRESSION DIAGNOSTICS
quietly regress pol_conf2 i.pid_strength year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
estat vif /*No multicollinearity problem based on accepted guidelines */
rvfplot /*Residuals show potential problem with heteroskedasticity due to ordinal outcomes; still justified to fit linear model (Angrist & Pischke)*/
avplots /* No clear outliers */
predict r, resid 
histogram r, normal	/*Somehwat non-normal errors, but sample size is large enough for central limit theorem to be in effect*/
qnorm r, grid /*Ditto*/
drop r
*/


***Table 2 - regular SE Models I & II (no clustered SE's)
/*Model I:
estimates clear 
set more off
regress pol_conf2 i.pid_strength##i.pid_idr year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo

*Model II: Omits PID control since no significant party difference (Dem vs Rep) and we wish to avoid multicolinearity 
quietly regress pol_conf2 i.pid_strength year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo
*margins pid_strength
*marginsplot

*Model III: Fixed effects version of Model I
quietly regress pol_conf2 i.pid_strength##i.pid_idr i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo 

*Model IV: Fixed effects version of Model II
quietly regress pol_conf2 i.pid_strength i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo 
margins pid_strength
marginsplot

esttab using Table2_SSR.rtf, b(3) se(3) ar2 ///
	label title (Table 2. Determinants of Political Trust) ///
	star(* .05 ** .01 *** .001) ///
	drop(0.tv_quart 1.pid_idr 1.pid_strength#1.pid_idr 1.pid_strength#2.pid_idr 2.pid_strength#1.pid_idr ///
	3.pid_strength#1.pid_idr 0.pid_strength) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" ) ///
	note("General Social Survey, 1972-2014. Entries are regression coefficients, followed by standard errors in parentheses. Models I and II, OLS; Models III and IV, fixed effects with year dummies (coefficients not shown)") replace
*/



***Table A2 - clustered SE Models I & II
/*Model I:  
estimates clear 
set more off
regress pol_conf2 i.pid_strength##i.pid_idr year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0, vce(cluster year)
eststo

*Model II: Omits PID control since no significant party difference (Dem vs Rep) and we wish to avoid multicolinearity 
quietly regress pol_conf2 i.pid_strength year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt], vce(cluster year)
eststo
*margins pid_strength

*Model III: Fixed effects version of Model I
quietly regress pol_conf2 i.pid_strength##i.pid_idr i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo 

*Model IV: Fixed effects version of Model II
quietly regress pol_conf2 i.pid_strength i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo 

esttab using Table_A2_SSR.rtf, b(3) se(3) ar2 ///
	label title (Table A2. Determinants of Political Trust) ///
	star(* .05 ** .01 *** .001) ///
	drop(0.tv_quart 1.pid_idr 1.pid_strength#1.pid_idr 1.pid_strength#2.pid_idr 2.pid_strength#1.pid_idr ///
	3.pid_strength#1.pid_idr 0.pid_strength) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" ) ///
	note("Source: General Social Survey, 1972-2014. Entries are coefficients of ordinary least squares regression, followed by standard errors. For Models I and II, standard errors are clustered on year; robust standard errors in parentheses. For Models III and IV, standard errors are not clustered; fixed effects specification is used with year dummy (coefficients not shown).") replace
*/

	

***DIAGNOSTIC FIGURES: SEPARATE VERSIONS FOR DEMS & REPS
/*Described in manuscript, but not presented, for parsimony.
*1st - DEMOCRATS ONLY
regress pol_conf2 i.dem_strength3 year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt], vce(cluster year)
margins dem_strength3
marginsplot

*2nd - REPUBLICANS ONLY
regress pol_conf2 i.rep_strength3 year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt], vce(cluster year)
margins rep_strength3
marginsplot
*/


********************************
************* GENERALIZED TRUST*
********************************
/*Table 3. Determinants of General Trust
*Model I
set more off
estimates clear
quietly regress gen_trust i.pid_strength##i.pid_idr year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo

*Model II: Omits PID control since no significant party difference (Dem vs Rep) and we wish to avoid multicolinearity 
quietly regress gen_trust i.pid_strength year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo
*margins pid_strength
*marginsplot

*Model III: Fixed effects version of Model I
quietly regress gen_trust i.pid_strength##i.pid_idr i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo 

*Model IV: Fixed effects version of Model II
quietly regress gen_trust i.pid_strength i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo 
margins pid_strength
marginsplot

*Table
esttab using Table3_SSR.rtf, b(3) se(3) ar2 ///
	label title (Table 3. Determinants of Generalized Trust) ///
	star(* .05 ** .01 *** .001) ///
	drop(0.tv_quart 1.pid_idr 1.pid_strength#1.pid_idr 1.pid_strength#2.pid_idr 2.pid_strength#1.pid_idr ///
	3.pid_strength#1.pid_idr 0.pid_strength) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" ) ///
	note("General Social Survey, 1972-2014. Entries are regression coefficients, followed by standard errors in parentheses. Models I and II, OLS; Models III and IV fixed effects with year dummies (coefficients not shown).") replace
*/


* Table A3 - with clustered SE for Models I and II
/*Model I
estimates clear
quietly regress gen_trust i.pid_strength##i.pid_idr year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0, vce(cluster year)
eststo

*Model II: Omits PID control since no significant party difference (Dem vs Rep) and we wish to avoid multicolinearity 
quietly regress gen_trust i.pid_strength year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt], vce(cluster year)
eststo
*margins pid_strength
*marginsplot

*Model III: Fixed effects version of Model I
quietly regress gen_trust i.pid_strength##i.pid_idr i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt] if pid_idr>0
eststo 

*Model IV: Fixed effects version of Model II
quietly 
regress gen_trust i.pid_strength i.year i.tv_quart news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency [pweight=compwt]
eststo 
*margins pid_strength
*marginsplot

*Table
esttab using Table_A3_SSR.rtf, b(3) se(3) ar2 ///
	label title (Table A3. Determinants of Generalized Trust) ///
	star(* .05 ** .01 *** .001) ///
	drop(0.tv_quart 1.pid_idr 1.pid_strength#1.pid_idr 1.pid_strength#2.pid_idr 2.pid_strength#1.pid_idr ///
	3.pid_strength#1.pid_idr 0.pid_strength) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" ) ///
	note("Source: General Social Survey, 1972-2014. Entries are coefficients of ordinary least squares regression, followed by standard errors. For Models I and II, standard errors are clustered on year; robust standard errors in parentheses. For Models III and IV, standard errors are not clustered; fixed effects specification is used with year dummy (coefficients not shown).") replace
*/

	
*****************************************
*************OVER TIME - POLITICAL TRUST*
*****************************************

/*****Table 4, Partisan strength and political trust over time - NO clustered standard errors
estimates clear
regress pol_conf2 c.year2##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 ///
	black otherrace ln_size incumbency [pweight=compwt]
eststo 

esttab using Table4_SSR.rtf, b(3) se(3) ///
	ar2 label title (Table 4. Partisan Strength and Political Trust Over Time) ///
	note("General Social Survey, 1972-2014. Entries are OLS regression coefficients, with standard errors in parentheses.") ///
	star(* .05 ** .01 *** .001)  drop(0.tv_quart) nogap replace

**** Tables 4 - BONFERRONI PAIRWISE COMPARISON, FOR TEXT
regress pol_conf2 c.year2##c.pidstr_c_indszero i.pid_idr i.tv_quart news_ age gender educ coninc attend2 ///
	black otherrace ln_size incumbency [pweight=compwt]	
margins pid_idr, pwcompare mcompare(bonferroni)
*/


****Table A4, Partisan strength and political trust over time - WITH clustered standard errors
/*
estimates clear
regress pol_conf2 c.year2##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 black otherrace ln_size incumbency[pweight=compwt], vce(cluster year)
eststo

esttab using Table_A4_SSR.rtf, b(3) se(3) ///
	ar2 label title (Table A4. Partisan Strength and Political Trust Over Time) ///
	drop (0.tv_quart) ///
	note("General Social Survey, 1972-2014. Entries are OLS regression coefficients, with standard errors clustered on year in parentheses.") ///
	star(* .05 ** .01 *** .001) nogap replace
*/

	
/* ROBUSTNESS TEST: FIXED EFFECTS MODELS
* Notes: This leads to a huge number of coefficients, unwieldy to interpret.
* Alternate presentation: margins plots
* Incumbency must be dropped because it is perfectly colinear with "year"
* Margins plots of the following models are the same because the models only change baseline for PID dummy

regress pol_conf2 i.year##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 ///
	black otherrace ln_size [pweight=compwt]
margins year, dydx(pidstr_c_indszero)
marginsplot, xlabel(, labsize(small) angle(forty_five)) xtitle(Year) ytitle(Marginal Effect of PID Strength)
*/


*********************************************
*************OVER TIME - GENERALIZED TRUST***
*********************************************

/*Table 5. Partisan strength and generalized trust over time	
estimates clear
regress gen_trust c.year2##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 black otherrace ln_size ///
	incumbency [pweight=compwt]
eststo 

esttab using Table5_SSR.rtf, b(3) se(3) ///
	ar2 label title (Table 5. Partisan Strength and Generalized Trust Over time) ///
	note("General Social Survey, 1972-2014. Entries are OLS regression coefficients, with standard errors in parentheses.") ///
	star(* .05 ** .01 *** .001) drop(0.tv_quart) nogap replace

**** Tables 5 - BONFERRONI PAIRWISE COMPARISON
regress gen_trust c.year2##c.pidstr_c_indszero i.pid_idr i.tv_quart news_ age gender educ coninc attend2 ///
	black otherrace ln_size incumbency [pweight=compwt]	
margins pid_idr, pwcompare mcompare(bonferroni)
*/
	


/****Table A5: Partisan strength and generalized trust over time - clustered SE's
set more off
estimates clear
regress gen_trust c.year2##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 black otherrace ln_size incumbency [pweight=compwt], vce(cluster year)
eststo

esttab using Table_A5_SSR.rtf, b(3) se(3) ar2 label  drop(0.tv_quart) title (Table A5. Partisan strength and general trust over time) ///
	note ("Source: General Social Survey, 1972-2014. Entries are coefficients of ordinary least squares regression with standard errors clustered on year; robust standard errors in parentheses.") ///
	star(* .05 ** .01 *** .001) nogap replace
*/


/* RERUN REGS AS FIXED EFFECTS MODELS
* Note.  This leads to a huge number of coefficients, tables may not be best summary.
* Use margins plots instead
* Also note that incumbency must be dropped because it is perfectly colinear with other variables

regress gen_trust i.year##c.pidstr_c_indszero dem rep i.tv_quart news_ age gender educ coninc attend2 black otherrace ln_size [pweight=compwt]
margins year, dydx(pidstr_c_indszero)
marginsplot, xlabel(, labsize(small) angle(forty_five)) xtitle(Year) ytitle(Marginal Effect of PID Strength)

*/




*****************************
**APPENDIX: FIML FOR MISSINGS
*****************************

***** Imputation is of questionable utility when data is missing for an entire year.
***** Instead, check models using full information maximum likelihood (FIML).
***** FIML is conducted using the sem command with the method(mlmv) option.
***** Since the sem command doesn't allow factor notation, it is necessary to create dummy variables.

/*
gen pid_lean   = pid_strength == 1
gen pid_weak   = pid_strength == 2
gen pid_strong = pid_strength == 3
foreach var of varlist pid_lean pid_weak pid_strong {
	replace `var' = . if missing(pid_strength)
}
lab var pid_lean   "PID: Lean"
lab var pid_weak   "PID: Weak"
lab var pid_strong "PID: Strong"

gen pid_dem = pid_idr == 1
gen pid_rep = pid_idr == 2
foreach var of varlist pid_dem pid_rep {
	replace `var' = . if missing(pid_idr)
}
lab var pid_dem "PID: Democrat"
lab var pid_rep "PID: Republican"

gen leanXdem = pid_lean*pid_dem
gen leanXrep = pid_lean*pid_rep
gen weakXdem = pid_weak*pid_dem
gen weakXrep = pid_weak*pid_rep
gen strongXdem = pid_strong*pid_dem
gen strongXrep = pid_strong*pid_rep
lab var leanXdem "PID Democrat X PID Lean"
lab var leanXrep "PID Republican X PID Lean"
lab var weakXdem "PID Democrat X PID Weak"
lab var weakXrep "PID Republican X PID Weak"
lab var strongXdem "PID Democrat X PID Strong"
lab var strongXrep "PID Republican X PID Strong"

gen tv_quart1 = tv_quart == 1
gen tv_quart2 = tv_quart == 2
gen tv_quart3 = tv_quart == 3
gen tv_quart4 = tv_quart == 4
foreach var of varlist tv_quart? {
	replace `var' = . if missing(tv_quart)
}
lab var tv_quart1 "TV View: 1st Quartile"
lab var tv_quart2 "TV View: 2nd Quartile"
lab var tv_quart3 "TV View: 3rd Quartile"
lab var tv_quart4 "TV View: 4th Quartile"

* Make year dummies, 1975 is reference
foreach y in 1978 1983 1986 1988 1989 1990 1991 1993 1994 1996 1998 2000 ///
	2002 2004 2006 2008 2010 2012 2014 {
	gen year_`y' = year == `y'
	lab var year_`y' "Year: `y'"
}

* Generate cubic polynomial for year. Mean center.
quietly sum year
gen cent_year  = year - r(mean)
gen sq_year    = cent_year^2
gen cub_year   = cent_year^3
lab var cent_year "Year (Mean Centered)"
lab var sq_year   "Year Squared"
lab var cub_year  "Year Cubed"
*/

/**** Political Trust
estimates clear 
set more off 

*(1) Model I 
estimates clear 
set more off 
sem (pol_conf2 <- pid_weak pid_strong pid_rep weakXrep strongXrep year tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ /// 
	age gender educ coninc attend2 black ///
	otherrace ln_size incumbency) [pweight=compwt] if pid_idr>0, method(mlmv)
eststo


*(2) Model II 
sem (pol_conf2 <- pid_lean pid_weak pid_strong year tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ /// 
	age gender educ coninc attend2 black ///
	otherrace ln_size incumbency) [pweight=compwt], method(mlmv)
eststo	


*(3) Model III
* Model won't converge with year dummies.  Add cubic polynomial instead.
sem (pol_conf2 <- pid_weak pid_strong pid_rep weakXrep strongXrep tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency cent_year sq_year cub_year) [pweight=compwt] if pid_idr>0, method(mlmv)
eststo

*(4) Model IV
sem (pol_conf2 <- pid_lean pid_weak pid_strong tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency cent_year sq_year cub_year) [pweight=compwt], method(mlmv)	
eststo
	
esttab using TableA6_Political_fiml.rtf, b(3) se(3) ///
	label title (Appendix Table A6. Determinants of Political Trust, FIML Estimator) ///
	star(* .05 ** .01 *** .001) ///
	drop(mean(*): var(*): cov(*):) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" "Model V" "Model VI" ) ///
	note("General Social Survey, 1972-2014. Entries are regression coefficients, followed by standard errors in parentheses. Models I and II, OLS; Models III and IV, year as cubic spline.") ///
	replace
*/


/**** Generalized Trust	
estimates clear 
set more off 

*(1) Model I 
sem (gen_trust  <- pid_weak pid_strong pid_rep weakXrep strongXrep year tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ /// 
	age gender educ coninc attend2 black ///
	otherrace ln_size incumbency) [pweight=compwt] if pid_idr>0, method(mlmv)
eststo

*(2) Model II 	
sem (gen_trust  <- pid_lean pid_weak pid_strong year tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ /// 
	age gender educ coninc attend2 black ///
	otherrace ln_size incumbency) [pweight=compwt], method(mlmv)
eststo	

*(3) Model III
* Model won't converge with year dummies.  Add cubic polynomial instead.
sem (gen_trust  <- pid_weak pid_strong pid_rep weakXrep strongXrep tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency cent_year sq_year cub_year) [pweight=compwt] if pid_idr>0, method(mlmv)
eststo

*(4) Model IV
sem (gen_trust  <- pid_lean pid_weak pid_strong tv_quart1 ///
	tv_quart2 tv_quart3 tv_quart4 news_ age gender educ coninc attend2 black ///
	otherrace ln_size incumbency cent_year sq_year cub_year) [pweight=compwt], method(mlmv)	
eststo
	
esttab using TableA7_General_fiml.rtf, b(3) se(3) ///
	label title (Table A7. Determinants of Generalized Trust, FIML Estimator) ///
	star(* .05 ** .01 *** .001) ///
	drop(mean(*): var(*): cov(*):) ///
	nogaps mtitles("Model I" "Model II" "Model III" "Model IV" ) ///
	note("General Social Survey, 1972-2014. Entries are regression coefficients, followed by standard errors in parentheses. Models I and II, OLS; Models III and IV, year as cubic spline.") ///
	replace
*/	
	

